package net.borlis.sample.services.configuration;

import net.borlis.annotations.version.Alpha;
import net.borlis.dictionaries.product.DeprecatedPaymentSystemDictionary;
import net.borlis.dictionaries.product.DeprecatedProductType;
import net.borlis.dictionaries.product.SaleType;
import net.borlis.sample.service.entities.configuration.interfaces.ITravelPeriodEntity;
import net.borlis.sample.service.entities.configuration.working.*;
import net.borlis.sample.service.entities.customer.DynamixAccountEntity;
import net.borlis.sample.service.entities.customer.DynamixCustomerEntity;
import net.borlis.sample.service.entities.customer.VitoXDynamixAccountEntity;
import net.borlis.sample.service.entities.customer.VitoXDynamixCustomerEntity;
import net.borlis.sample.service.entities.general.*;
import net.borlis.sample.services.api.IVitoService;
import net.borlis.sample.services.common.ServiceRepoProvider;
import net.borlis.sample.services.declaration.TravelPeriodService;
import net.borlis.sample.services.declaration.output.TravelPeriodObject;
import net.borlis.errors.exceptions.ServerException;
import junit.framework.Assert;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.persistence.PersistenceException;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import static net.borlis.dictionaries.product.LifecycleStateDictionary.WORKING_COPY;

/**
 * The demo configuration creator - object for UI testing will be created.
 *
 * @author alex@borlis.net
 */
@RequestScoped
public class ServiceDemoEnvCreator extends ServiceDemoEnvCleaner {

    private static final String EN_GB_LOCALE = "en-GB";

    public static final Long YURIY_TT_AUTH_ID_MOCKED = new Long(99999);
    public static final Long ALEX_TT_AUTH_ID_MOCKED = new Long(77777);
    public static final Long SERGEY_TT_AUTH_ID_MOCKED = new Long(88888);

    private static final Long TTADMIN_TT_AUTH_ID_MOCKED = new Long(78769);
    private static final Long TTUSER_TT_AUTH_ID_MOCKED = new Long(78771);
    private static final Long VITOUSER_TT_AUTH_ID_MOCKED = new Long(78775);
    private static final Long VITOSUPERVISOR_TT_AUTH_ID_MOCKED = new Long(78773);

    private static final Double VITO_DEFAULT_FIRST_MARGIN = new Double(1);
    private static final Double VITO_DEFAULT_RELATIVE_MARGIN = new Double(2);
    private static final Double VITO_DEFAULT_SECOND_MARGIN = new Double(3);

    private static final Integer RELEASE_DAYS_TEST = 7;

    private static final Long YURIY_VITO_KID = new Long(78769);
    private static final Long ALEX_VITO_KID = new Long(5654647);
    private static final Long SERGEY_VITO_KID = new Long(8796789);


    @Inject
    private Logger logger;

    @Inject
    private ServiceRepoProvider repoProvider;

    @Inject @Alpha
    private IVitoService vitoService;

    @Inject @Alpha
    private TravelPeriodService travelPeriodService;

    private DynamixAccountEntity ttuser;
    private DynamixAccountEntity ttadmin;
    private DynamixAccountEntity vitouser;
    private DynamixAccountEntity vitosupervisor;

    public ServiceDemoEnvCreator() {
    }

    public void prepareEnvironment() /* throws ServerException */ {
        clearEnvironment();
        initEnvironment();
    }

    public void initEnvironment() /* throws ServerException */ {


        logger.info("create the db -> started");

        try {
            //could not create base locales from java, already created from dictionaries

            DynamixLocaleEntity localeDE = repoProvider.getDynamixLocaleRepository().find("de-DE");
            Assert.assertNotNull(localeDE.getId());
            DynamixLocaleEntity localeUA = repoProvider.getDynamixLocaleRepository().find("ua-UA");
            Assert.assertNotNull(localeUA.getId());
            DynamixLocaleEntity localeEN = repoProvider.getDynamixLocaleRepository().find(EN_GB_LOCALE);
            Assert.assertNotNull(localeEN.getId());

            repoProvider.getCurrencyRepository().beginTransaction();
            CurrencyEntity currencyEuro = new CurrencyEntity("EUR");
            repoProvider.getCurrencyRepository().create(currencyEuro);
            repoProvider.getCurrencyRepository().commitTransaction();

            repoProvider.getCurrencyDetailRepository().beginTransaction();
            CurrencyDetailEntity currencyDetailDE = new CurrencyDetailEntity("euro de", "deutsch euro", currencyEuro, localeDE);
            repoProvider.getCurrencyDetailRepository().create(currencyDetailDE);
            CurrencyDetailEntity currencyDetailUA = new CurrencyDetailEntity("євро", "європейські гроші", currencyEuro, localeUA);
            repoProvider.getCurrencyDetailRepository().create(currencyDetailUA);
            CurrencyDetailEntity currencyDetailEN = new CurrencyDetailEntity("euro en", "european money", currencyEuro, localeEN);
            repoProvider.getCurrencyDetailRepository().create(currencyDetailEN);
            repoProvider.getCurrencyDetailRepository().commitTransaction();

            repoProvider.getCountryRepository().beginTransaction();
            CountryEntity germany = new CountryEntity("DE", currencyEuro);
            repoProvider.getCountryRepository().create(germany);
            CountryEntity ukraine = new CountryEntity("UA", currencyEuro);
            repoProvider.getCountryRepository().create(ukraine);
            CountryEntity england = new CountryEntity("EN", currencyEuro);
            repoProvider.getCountryRepository().create(england);
            repoProvider.getCountryRepository().commitTransaction();

            repoProvider.getCountryDetailRepository().beginTransaction();
            CountryDetailEntity germanyDetailDE = new CountryDetailEntity("Deutschland", germany, localeDE);
            repoProvider.getCountryDetailRepository().create(germanyDetailDE);
            CountryDetailEntity germanyDetailUA = new CountryDetailEntity("Німеччина", germany, localeUA);
            repoProvider.getCountryDetailRepository().create(germanyDetailUA);
            CountryDetailEntity germanyDetailEN = new CountryDetailEntity("Germany", germany, localeEN);
            repoProvider.getCountryDetailRepository().create(germanyDetailEN);

            CountryDetailEntity ukraineDetailDE = new CountryDetailEntity("Ukraine DE", ukraine, localeDE);
            repoProvider.getCountryDetailRepository().create(ukraineDetailDE);
            CountryDetailEntity ukraineDetailUA = new CountryDetailEntity("Украіна", ukraine, localeUA);
            repoProvider.getCountryDetailRepository().create(ukraineDetailUA);
            CountryDetailEntity ukraineDetailEN = new CountryDetailEntity("Ukraine EN", ukraine, localeEN);
            repoProvider.getCountryDetailRepository().create(ukraineDetailEN);

            CountryDetailEntity englandDetailDE = new CountryDetailEntity("England DE", england, localeDE);
            repoProvider.getCountryDetailRepository().create(englandDetailDE);
            CountryDetailEntity englandDetailUA = new CountryDetailEntity("Англія", england, localeUA);
            repoProvider.getCountryDetailRepository().create(englandDetailUA);
            CountryDetailEntity englandDetailEN = new CountryDetailEntity("England EN", england, localeEN);
            repoProvider.getCountryDetailRepository().create(englandDetailEN);
            repoProvider.getCountryDetailRepository().commitTransaction();

            repoProvider.getDynamixCustomerRepository().beginTransaction();
            DynamixCustomerEntity amadeusTeamCustomer = new DynamixCustomerEntity("AMADEUS_KYIV", "DEV TEAM AMADEUS");
            repoProvider.getDynamixCustomerRepository().create(amadeusTeamCustomer);
            repoProvider.getDynamixCustomerRepository().commitTransaction();

            repoProvider.getDynamixAccountRepository().beginTransaction();
            DynamixAccountEntity yuryAccount = new DynamixAccountEntity("Yury", "D", "yury_dadyshin", YURIY_TT_AUTH_ID_MOCKED, amadeusTeamCustomer);
            repoProvider.getDynamixAccountRepository().create(yuryAccount);
            DynamixAccountEntity alexAccount = new DynamixAccountEntity("Alex", "Borlis", "alex_borlis", ALEX_TT_AUTH_ID_MOCKED, amadeusTeamCustomer);
            repoProvider.getDynamixAccountRepository().create(alexAccount);
            DynamixAccountEntity sergeyAccount = new DynamixAccountEntity("Sergey", "Mavrov", "serg_mavrov", SERGEY_TT_AUTH_ID_MOCKED, amadeusTeamCustomer);
            repoProvider.getDynamixAccountRepository().create(sergeyAccount);
            repoProvider.getDynamixAccountRepository().commitTransaction();

            repoProvider.getDynamixAccountRepository().beginTransaction();
            ttadmin = new DynamixAccountEntity("TT Admin", "TT Admin", "dynamicpackagingconfig-ttadmin", TTADMIN_TT_AUTH_ID_MOCKED, amadeusTeamCustomer);
            repoProvider.getDynamixAccountRepository().create(ttadmin);
            ttuser = new DynamixAccountEntity("TT User", "TT User", "dynamicpackagingconfig-ttuser", TTUSER_TT_AUTH_ID_MOCKED, amadeusTeamCustomer);
            repoProvider.getDynamixAccountRepository().create(ttuser);
            vitouser = new DynamixAccountEntity("Vito User", "Vito User", "dynamicpackagingconfig-vitouser", VITOUSER_TT_AUTH_ID_MOCKED, amadeusTeamCustomer);
            repoProvider.getDynamixAccountRepository().create(vitouser);
            vitosupervisor = new DynamixAccountEntity("Vito Supervisor", "Vito Supervisor", "dynamicpackagingconfig-vitosupervisor", VITOSUPERVISOR_TT_AUTH_ID_MOCKED, amadeusTeamCustomer);
            repoProvider.getDynamixAccountRepository().create(vitosupervisor);
            repoProvider.getDynamixAccountRepository().commitTransaction();

            // -=-=-=-
            // qa users
            repoProvider.getDynamixAccountRepository().beginTransaction();

            final Long dpctQaTtAdminID = (long)78967;
            DynamixAccountEntity dpctQaTtAdmin = new DynamixAccountEntity("dpctQaTtAdmin", "dpctQaTtAdmin", "dpctQaTtAdmin",
                    dpctQaTtAdminID, amadeusTeamCustomer);
            repoProvider.getDynamixAccountRepository().create(dpctQaTtAdmin);

            final Long dpctQaTtUserID = (long)78965;
            DynamixAccountEntity dpctQaTtUser = new DynamixAccountEntity("dpctQaTtUser", "dpctQaTtUser", "dpctQaTtUser",
                    dpctQaTtUserID, amadeusTeamCustomer);
            repoProvider.getDynamixAccountRepository().create(dpctQaTtUser);

            final Long dpctQaVitoUserID = (long)78971;
            DynamixAccountEntity dpctQaVitoUser = new DynamixAccountEntity("dpctQaVitoUser", "dpctQaVitoUser", "dpctQaVitoUser",
                    dpctQaVitoUserID, amadeusTeamCustomer);
            repoProvider.getDynamixAccountRepository().create(dpctQaVitoUser);

            final Long dpctQaTtVitoSupervisorID = (long)78969;
            DynamixAccountEntity dpctQaTtVitoSupervisor = new DynamixAccountEntity("dpctQaTtVitoSupervisor", "dpctQaTtVitoSupervisor", "dpctQaTtVitoSupervisor",
                    dpctQaTtVitoSupervisorID, amadeusTeamCustomer);
            repoProvider.getDynamixAccountRepository().create(dpctQaTtVitoSupervisor);
            repoProvider.getDynamixAccountRepository().commitTransaction();
            // -=-=-=-

            repoProvider.getMainOrganisationRepository(WORKING_COPY).beginTransaction();
            final long cdsMoYura = 123456;
            AttachedMainOrganisationWorking moVitoYura = new AttachedMainOrganisationWorking(cdsMoYura, "123456", yuryAccount);
            repoProvider.getMainOrganisationRepository(WORKING_COPY).create(moVitoYura);
            final long cdsMoAlex = 123457;
            AttachedMainOrganisationWorking moVitoAlex = new AttachedMainOrganisationWorking(cdsMoAlex, "123457", alexAccount);
            repoProvider.getMainOrganisationRepository(WORKING_COPY).create(moVitoAlex);
            final long cdsMoSergey = 123458;
            AttachedMainOrganisationWorking moVitoSergey = new AttachedMainOrganisationWorking(cdsMoSergey, "123458", sergeyAccount);
            repoProvider.getMainOrganisationRepository(WORKING_COPY).create(moVitoSergey);
            repoProvider.getMainOrganisationRepository(WORKING_COPY).commitTransaction();

            final Integer startYury = 1;
            final Integer finishYury = 10;
            List<TravelDurationEntity> travelDurationEntityListYury = new ArrayList<>(Arrays.asList(new TravelDurationEntity(startYury, finishYury)));

//            repoProvider.getVitoRepository(WORKING_COPY).beginTransaction();
            vitoService.createVito(WORKING_COPY, EN_GB_LOCALE, "DADYSH", "YURA&KATE", YURIY_VITO_KID.toString(),
                    ukraine.getCode(), yuryAccount.getTtAuthId(), VITO_DEFAULT_FIRST_MARGIN,
                    VITO_DEFAULT_RELATIVE_MARGIN, VITO_DEFAULT_SECOND_MARGIN, RELEASE_DAYS_TEST, travelDurationEntityListYury);
            VitoWorking vitoYura = (VitoWorking) vitoService.getVito(WORKING_COPY, EN_GB_LOCALE,"DADYSH",yuryAccount.getTtAuthId()).getVito();
//            repoProvider.getVitoRepository(WORKING_COPY).commitTransaction();

            final Integer startAlex = 2;
            final Integer finishAlex = 8;
//            repoProvider.getVitoRepository(WORKING_COPY).beginTransaction();
            List<TravelDurationEntity> travelDurationEntityListAlex = new ArrayList<>(Arrays.asList(new TravelDurationEntity(startAlex, finishAlex)));
            vitoService.createVito(WORKING_COPY, EN_GB_LOCALE, "BORLIS", "ALEX&OLGA", ALEX_VITO_KID.toString(),
                    ukraine.getCode(), alexAccount.getTtAuthId(), VITO_DEFAULT_FIRST_MARGIN,
                    VITO_DEFAULT_RELATIVE_MARGIN, VITO_DEFAULT_SECOND_MARGIN, RELEASE_DAYS_TEST, travelDurationEntityListAlex);
            VitoWorking vitoAlex = (VitoWorking) vitoService.getVito(WORKING_COPY, EN_GB_LOCALE,"BORLIS",alexAccount.getTtAuthId()).getVito();
//            repoProvider.getVitoRepository(WORKING_COPY).commitTransaction();

            final Integer startSergey = 2;
            final Integer finishSergey = 8;
//            repoProvider.getVitoRepository(WORKING_COPY).beginTransaction();
            List<TravelDurationEntity> travelDurationEntityListVitoSergey = new ArrayList<>(Arrays.asList(new TravelDurationEntity(startSergey, finishSergey)));
            vitoService.createVito(WORKING_COPY, EN_GB_LOCALE, "MAVROV", "SERG&OXANA", SERGEY_VITO_KID.toString(),
                    germany.getCode(), sergeyAccount.getTtAuthId(), VITO_DEFAULT_FIRST_MARGIN,
                    VITO_DEFAULT_RELATIVE_MARGIN, VITO_DEFAULT_SECOND_MARGIN, RELEASE_DAYS_TEST, travelDurationEntityListVitoSergey);
            VitoWorking vitoSergey = (VitoWorking) vitoService.getVito(WORKING_COPY, EN_GB_LOCALE,"BORLIS",sergeyAccount.getTtAuthId()).getVito();
//            repoProvider.getVitoRepository(WORKING_COPY).commitTransaction();

            repoProvider.getVitoXDynamixCustomerRepository().beginTransaction();
            VitoXDynamixCustomerEntity yuriyVitoXAmadeusCustomer = new VitoXDynamixCustomerEntity(vitoYura, amadeusTeamCustomer);
            repoProvider.getVitoXDynamixCustomerRepository().create(yuriyVitoXAmadeusCustomer);
            VitoXDynamixCustomerEntity alexVitoXAmadeusCustomer = new VitoXDynamixCustomerEntity(vitoAlex, amadeusTeamCustomer);
            repoProvider.getVitoXDynamixCustomerRepository().create(alexVitoXAmadeusCustomer);
            VitoXDynamixCustomerEntity sergeyVitoXAmadeusCustomer = new VitoXDynamixCustomerEntity(vitoSergey, amadeusTeamCustomer);
            repoProvider.getVitoXDynamixCustomerRepository().create(sergeyVitoXAmadeusCustomer);
            repoProvider.getVitoXDynamixCustomerRepository().commitTransaction();

            repoProvider.getVitoXDynamixAccountRepository().beginTransaction();
            VitoXDynamixAccountEntity yuriyAccountXYuriyVito = new VitoXDynamixAccountEntity(vitoYura, yuryAccount);
            repoProvider.getVitoXDynamixAccountRepository().create(yuriyAccountXYuriyVito);
            VitoXDynamixAccountEntity alexAccountXAlexVito = new VitoXDynamixAccountEntity(vitoAlex, alexAccount);
            repoProvider.getVitoXDynamixAccountRepository().create(alexAccountXAlexVito);
            VitoXDynamixAccountEntity sergeyAccountXSergeyVito = new VitoXDynamixAccountEntity(vitoSergey, sergeyAccount);
            repoProvider.getVitoXDynamixAccountRepository().create(sergeyAccountXSergeyVito);

            //provide tt-admin user with all amadeus VITO's access
            VitoXDynamixAccountEntity ttadminAccountXSergeyVito = new VitoXDynamixAccountEntity(vitoSergey, ttadmin);
            repoProvider.getVitoXDynamixAccountRepository().create(ttadminAccountXSergeyVito);
            VitoXDynamixAccountEntity ttadminAccountXAlexVito = new VitoXDynamixAccountEntity(vitoAlex, ttadmin);
            repoProvider.getVitoXDynamixAccountRepository().create(ttadminAccountXAlexVito);
            VitoXDynamixAccountEntity ttadminAccountXYuriyVito = new VitoXDynamixAccountEntity(vitoYura, ttadmin);
            repoProvider.getVitoXDynamixAccountRepository().create(ttadminAccountXYuriyVito);

            VitoXDynamixAccountEntity ttuserAccountXSergeyVito = new VitoXDynamixAccountEntity(vitoSergey, ttuser);
            repoProvider.getVitoXDynamixAccountRepository().create(ttuserAccountXSergeyVito);
            VitoXDynamixAccountEntity ttuserAccountXAlexVito = new VitoXDynamixAccountEntity(vitoAlex, ttuser);
            repoProvider.getVitoXDynamixAccountRepository().create(ttuserAccountXAlexVito);
            VitoXDynamixAccountEntity ttuserAccountXYuriyVito = new VitoXDynamixAccountEntity(vitoYura, ttuser);
            repoProvider.getVitoXDynamixAccountRepository().create(ttuserAccountXYuriyVito);

            VitoXDynamixAccountEntity vitouserAccountXSergeyVito = new VitoXDynamixAccountEntity(vitoSergey, vitouser);
            repoProvider.getVitoXDynamixAccountRepository().create(vitouserAccountXSergeyVito);
            VitoXDynamixAccountEntity vitouserAccountXAlexVito = new VitoXDynamixAccountEntity(vitoAlex, vitouser);
            repoProvider.getVitoXDynamixAccountRepository().create(vitouserAccountXAlexVito);
            VitoXDynamixAccountEntity vitouserAccountXYuriyVito = new VitoXDynamixAccountEntity(vitoYura, vitouser);
            repoProvider.getVitoXDynamixAccountRepository().create(vitouserAccountXYuriyVito);

            VitoXDynamixAccountEntity vitosupervisorAccountXSergeyVito = new VitoXDynamixAccountEntity(vitoSergey, vitosupervisor);
            repoProvider.getVitoXDynamixAccountRepository().create(vitosupervisorAccountXSergeyVito);
            VitoXDynamixAccountEntity vitosupervisorAccountXAlexVito = new VitoXDynamixAccountEntity(vitoAlex, vitosupervisor);
            repoProvider.getVitoXDynamixAccountRepository().create(vitosupervisorAccountXAlexVito);
            VitoXDynamixAccountEntity vitosupervisorAccountXYuriyVito = new VitoXDynamixAccountEntity(vitoYura, vitosupervisor);
            repoProvider.getVitoXDynamixAccountRepository().create(vitosupervisorAccountXYuriyVito);

            repoProvider.getVitoXDynamixAccountRepository().commitTransaction();

            repoProvider.getCombinedRepository().beginTransaction();
            DynamixProviderTypeEntity typeFlight = getRepoProvider().getTypeRepository().findByProductType(DeprecatedProductType.FLIGHT);
            DynamixProviderSubtypeEntity subTypeCharter = new DynamixProviderSubtypeEntity("Charter", "Private flight option");
            CombinedDynamixProviderTypeEntity combTypeFlightCharter = new CombinedDynamixProviderTypeEntity("Flight-Charter", "", typeFlight, subTypeCharter);
            repoProvider.getCombinedRepository().create(combTypeFlightCharter);
            DynamixProviderTypeEntity typeHotel = getRepoProvider().getTypeRepository().findByProductType(DeprecatedProductType.HOTEL);
            DynamixProviderSubtypeEntity subTypeHostel = new DynamixProviderSubtypeEntity("Hostel", "Very cheap hotel");
            CombinedDynamixProviderTypeEntity combTypeHotelHostel = new CombinedDynamixProviderTypeEntity("Hotel-Hostel", "", typeHotel, subTypeHostel);
            repoProvider.getCombinedRepository().create(combTypeHotelHostel);
            repoProvider.getCombinedRepository().commitTransaction();

            repoProvider.getProviderRepository().beginTransaction();
            ProviderEntity providerMetro = new ProviderEntity("METRO");
            repoProvider.getProviderRepository().create(providerMetro);
            ProviderEntity providerCinema = new ProviderEntity("CINEMA");
            repoProvider.getProviderRepository().create(providerCinema);
            ProviderEntity providerTravel = new ProviderEntity("TRAVEL");
            repoProvider.getProviderRepository().create(providerTravel);
            repoProvider.getProviderRepository().commitTransaction();

            repoProvider.getDynamixProviderRepository().beginTransaction();
            final long cdsDynProviderMetro = 123789;
            DynamixProviderEntity dynProviderMetroUA = new DynamixProviderEntity(cdsDynProviderMetro, "MTR.UA", providerMetro, ukraine);
            repoProvider.getDynamixProviderRepository().create(dynProviderMetroUA);
            final long cdsDynProviderCinema = 123790;
            DynamixProviderEntity dynProviderCinemaUA = new DynamixProviderEntity(cdsDynProviderCinema, "CNM.UA", providerCinema, ukraine);
            repoProvider.getDynamixProviderRepository().create(dynProviderCinemaUA);
            final long cdsDynProviderTravel = 123791;
            DynamixProviderEntity dynProviderTravelUA = new DynamixProviderEntity(cdsDynProviderTravel, "TRV.UA", providerTravel, ukraine);
            repoProvider.getDynamixProviderRepository().create(dynProviderTravelUA);

            DynamixProviderEntity dynProviderMetroDE = new DynamixProviderEntity(cdsDynProviderMetro, "MTR.DE", providerMetro, germany);
            repoProvider.getDynamixProviderRepository().create(dynProviderMetroDE);
            DynamixProviderEntity dynProviderCinemaDE = new DynamixProviderEntity(cdsDynProviderCinema, "CNM.DE", providerCinema, germany);
            repoProvider.getDynamixProviderRepository().create(dynProviderCinemaDE);
            DynamixProviderEntity dynProviderTravelDE0 = new DynamixProviderEntity(cdsDynProviderTravel, "TRV0.DE", providerTravel, germany);
            repoProvider.getDynamixProviderRepository().create(dynProviderTravelDE0);

            DynamixProviderEntity dynProviderTravelDE1 = new DynamixProviderEntity(cdsDynProviderTravel, "TRV1.DE", providerTravel, germany);
            repoProvider.getDynamixProviderRepository().create(dynProviderTravelDE0);
            DynamixProviderEntity dynProviderTravelDE2 = new DynamixProviderEntity(cdsDynProviderTravel, "TRV2.DE", providerTravel, germany);
            repoProvider.getDynamixProviderRepository().create(dynProviderTravelDE0);
            DynamixProviderEntity dynProviderTravelDE3 = new DynamixProviderEntity(cdsDynProviderTravel, "TRV3.DE", providerTravel, germany);
            repoProvider.getDynamixProviderRepository().create(dynProviderTravelDE0);
            DynamixProviderEntity dynProviderTravelDE4 = new DynamixProviderEntity(cdsDynProviderTravel, "TRV4.DE", providerTravel, germany);
            repoProvider.getDynamixProviderRepository().create(dynProviderTravelDE0);
            repoProvider.getDynamixProviderRepository().commitTransaction();

            repoProvider.getDynamixProviderDetailRepository().beginTransaction();
            DynamixProviderDetailEntity dynProviderMetroUALocaleDE = new DynamixProviderDetailEntity("DEUTSCH MTR.UA", localeDE, dynProviderMetroUA);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderMetroUALocaleDE);
            DynamixProviderDetailEntity dynProviderMetroUALocaleUA = new DynamixProviderDetailEntity("Укр MTR.UA", localeUA, dynProviderMetroUA);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderMetroUALocaleUA);
            DynamixProviderDetailEntity dynProviderMetroUALocaleEN = new DynamixProviderDetailEntity("ENGLISH MTR.UA", localeEN, dynProviderMetroUA);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderMetroUALocaleEN);

            DynamixProviderDetailEntity dynProviderCinemaUALocaleDE = new DynamixProviderDetailEntity("DEUTSCH CNM.UA", localeDE, dynProviderCinemaUA);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderCinemaUALocaleDE);
            DynamixProviderDetailEntity dynProviderCinemaUALocaleUA = new DynamixProviderDetailEntity("Укр CNM.UA", localeUA, dynProviderCinemaUA);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderCinemaUALocaleUA);
            DynamixProviderDetailEntity dynProviderCinemaUALocaleEN = new DynamixProviderDetailEntity("ENGLISH CNM.UA", localeEN, dynProviderCinemaUA);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderCinemaUALocaleEN);

            DynamixProviderDetailEntity dynProviderTravelUALocaleDE = new DynamixProviderDetailEntity("DEUTSCH TRV.UA", localeDE, dynProviderTravelUA);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderTravelUALocaleDE);
            DynamixProviderDetailEntity dynProviderTravelUALocaleUA = new DynamixProviderDetailEntity("Укр TRV.UA", localeUA, dynProviderTravelUA);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderTravelUALocaleUA);
            DynamixProviderDetailEntity dynProviderTravelUALocaleEN = new DynamixProviderDetailEntity("ENGLISH TRV.UA", localeEN, dynProviderTravelUA);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderTravelUALocaleEN);

            DynamixProviderDetailEntity dynProviderMetroDELocaleDE = new DynamixProviderDetailEntity("DEUTSCH MTR.DE", localeDE, dynProviderMetroDE);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderMetroDELocaleDE);
            DynamixProviderDetailEntity dynProviderMetroDELocaleUA = new DynamixProviderDetailEntity("Укр MTR.DE", localeUA, dynProviderMetroDE);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderMetroDELocaleUA);
            DynamixProviderDetailEntity dynProviderMetroDELocaleEN = new DynamixProviderDetailEntity("ENGLISH MTR.DE", localeEN, dynProviderMetroDE);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderMetroDELocaleEN);

            DynamixProviderDetailEntity dynProviderCinemaDELocaleDE = new DynamixProviderDetailEntity("DEUTSCH CNM.DE", localeDE, dynProviderCinemaDE);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderCinemaDELocaleDE);
            DynamixProviderDetailEntity dynProviderCinemaDELocaleUA = new DynamixProviderDetailEntity("Укр CNM.DE", localeUA, dynProviderCinemaDE);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderCinemaDELocaleUA);
            DynamixProviderDetailEntity dynProviderCinemaDELocaleEN = new DynamixProviderDetailEntity("ENGLISH CNM.DE", localeEN, dynProviderCinemaDE);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderCinemaDELocaleEN);

            DynamixProviderDetailEntity dynProviderTravelDELocaleDE0 = new DynamixProviderDetailEntity("DEUTSCH TRV0.DE", localeDE, dynProviderTravelDE0);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderTravelDELocaleDE0);
            DynamixProviderDetailEntity dynProviderTravelDE0LocaleUA0 = new DynamixProviderDetailEntity("Укр TRV0.DE", localeUA, dynProviderTravelDE0);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderTravelDE0LocaleUA0);
            DynamixProviderDetailEntity dynProviderTravelDE0LocaleEN0 = new DynamixProviderDetailEntity("ENGLISH TRV0.DE", localeEN, dynProviderTravelDE0);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderTravelDE0LocaleEN0);

            DynamixProviderDetailEntity dynProviderTravelDELocaleDE1 = new DynamixProviderDetailEntity("DEUTSCH TRV1.DE", localeDE, dynProviderTravelDE1);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderTravelDELocaleDE1);
            DynamixProviderDetailEntity dynProviderTravelDELocaleUA1 = new DynamixProviderDetailEntity("Укр TRV1.DE", localeUA, dynProviderTravelDE1);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderTravelDELocaleUA1);
            DynamixProviderDetailEntity dynProviderTravelDELocaleEN1 = new DynamixProviderDetailEntity("ENGLISH TRV1.DE", localeEN, dynProviderTravelDE1);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderTravelDELocaleEN1);

            DynamixProviderDetailEntity dynProviderTravelDELocaleDE2 = new DynamixProviderDetailEntity("DEUTSCH TRV2.DE", localeDE, dynProviderTravelDE2);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderTravelDELocaleDE2);
            DynamixProviderDetailEntity dynProviderTravelDELocaleUA2 = new DynamixProviderDetailEntity("Укр TRV2.DE", localeUA, dynProviderTravelDE2);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderTravelDELocaleUA2);
            DynamixProviderDetailEntity dynProviderTravelDELocaleEN2 = new DynamixProviderDetailEntity("ENGLISH TRV2.DE", localeEN, dynProviderTravelDE2);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderTravelDELocaleEN2);

            DynamixProviderDetailEntity dynProviderTravelDELocaleDE3 = new DynamixProviderDetailEntity("DEUTSCH TRV3.DE", localeDE, dynProviderTravelDE3);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderTravelDELocaleDE3);
            DynamixProviderDetailEntity dynProviderTravelDELocaleUA3 = new DynamixProviderDetailEntity("Укр TRV3.DE", localeUA, dynProviderTravelDE3);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderTravelDELocaleUA3);
            DynamixProviderDetailEntity dynProviderTravelDELocaleEN3 = new DynamixProviderDetailEntity("ENGLISH TRV3.DE", localeEN, dynProviderTravelDE3);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderTravelDELocaleEN3);

            DynamixProviderDetailEntity dynProviderTravelDELocaleDE4 = new DynamixProviderDetailEntity("DEUTSCH TRV4.DE", localeDE, dynProviderTravelDE4);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderTravelDELocaleDE4);
            DynamixProviderDetailEntity dynProviderTravelDELocaleUA4 = new DynamixProviderDetailEntity("Укр TRV4.DE", localeUA, dynProviderTravelDE4);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderTravelDELocaleUA4);
            DynamixProviderDetailEntity dynProviderTravelDELocaleEN4 = new DynamixProviderDetailEntity("ENGLISH TRV4.DE", localeEN, dynProviderTravelDE4);
            repoProvider.getDynamixProviderDetailRepository().create(dynProviderTravelDELocaleEN4);
            repoProvider.getDynamixProviderDetailRepository().commitTransaction();

            repoProvider.getTypedDynamixProviderRepository().beginTransaction();
            TypedDynamixProviderEntity dynProviderMetroUAFlight = new TypedDynamixProviderEntity(dynProviderMetroUA, combTypeFlightCharter);
            repoProvider.getTypedDynamixProviderRepository().create(dynProviderMetroUAFlight);
            TypedDynamixProviderEntity dynProviderCinemaUAHotel = new TypedDynamixProviderEntity(dynProviderCinemaUA, combTypeHotelHostel);
            repoProvider.getTypedDynamixProviderRepository().create(dynProviderCinemaUAHotel);
            TypedDynamixProviderEntity dynProviderTravelUAFlight = new TypedDynamixProviderEntity(dynProviderTravelUA, combTypeFlightCharter);
            repoProvider.getTypedDynamixProviderRepository().create(dynProviderTravelUAFlight);
            TypedDynamixProviderEntity dynProviderMetroDEFlight = new TypedDynamixProviderEntity(dynProviderMetroDE, combTypeFlightCharter);
            repoProvider.getTypedDynamixProviderRepository().create(dynProviderMetroDEFlight);
            TypedDynamixProviderEntity dynProviderCinemaDEHotel = new TypedDynamixProviderEntity(dynProviderCinemaDE, combTypeHotelHostel);
            repoProvider.getTypedDynamixProviderRepository().create(dynProviderCinemaDEHotel);
            TypedDynamixProviderEntity dynProviderTravelDEFlight0 = new TypedDynamixProviderEntity(dynProviderTravelDE0, combTypeFlightCharter);
            repoProvider.getTypedDynamixProviderRepository().create(dynProviderTravelDEFlight0);

            TypedDynamixProviderEntity dynProviderTravelDEHotel1 = new TypedDynamixProviderEntity(dynProviderTravelDE1, combTypeHotelHostel);
            repoProvider.getTypedDynamixProviderRepository().create(dynProviderTravelDEHotel1);
            TypedDynamixProviderEntity dynProviderTravelDEHotel2 = new TypedDynamixProviderEntity(dynProviderTravelDE2, combTypeHotelHostel);
            repoProvider.getTypedDynamixProviderRepository().create(dynProviderTravelDEHotel2);
            TypedDynamixProviderEntity dynProviderTravelDEHotel3 = new TypedDynamixProviderEntity(dynProviderTravelDE3, combTypeHotelHostel);
            repoProvider.getTypedDynamixProviderRepository().create(dynProviderTravelDEHotel3);
            TypedDynamixProviderEntity dynProviderTravelDEHotel4 = new TypedDynamixProviderEntity(dynProviderTravelDE4, combTypeHotelHostel);
            repoProvider.getTypedDynamixProviderRepository().create(dynProviderTravelDEHotel4);
            repoProvider.getTypedDynamixProviderRepository().commitTransaction();

            repoProvider.getVitoConfigurationRepository(WORKING_COPY).beginTransaction();
            //todo:: check countries?
            VitoConfigurationWorking vitoYuraDynProviderMetroUAFlight = new VitoConfigurationWorking(true, SaleType.Total, vitoYura, dynProviderMetroUAFlight, yuryAccount);
            repoProvider.getVitoConfigurationRepository(WORKING_COPY).create(vitoYuraDynProviderMetroUAFlight);
            VitoConfigurationWorking vitoYuraDynProviderCinemaUAHotel = new VitoConfigurationWorking(true, SaleType.Total, vitoYura, dynProviderCinemaUAHotel, yuryAccount);
            repoProvider.getVitoConfigurationRepository(WORKING_COPY).create(vitoYuraDynProviderCinemaUAHotel);


            VitoConfigurationWorking vitoAlexDynProviderMetroUAFlight = new VitoConfigurationWorking(true, SaleType.Total, vitoAlex, dynProviderMetroUAFlight, alexAccount);
            repoProvider.getVitoConfigurationRepository(WORKING_COPY).create(vitoAlexDynProviderMetroUAFlight);
            VitoConfigurationWorking vitoAlexDynProviderCinemaUAHotel = new VitoConfigurationWorking(true, SaleType.Total, vitoAlex, dynProviderCinemaUAHotel, alexAccount);
            repoProvider.getVitoConfigurationRepository(WORKING_COPY).create(vitoAlexDynProviderCinemaUAHotel);
            VitoConfigurationWorking vitoAlexDynProviderTravelUAFlight = new VitoConfigurationWorking(true, SaleType.Total, vitoAlex, dynProviderTravelUAFlight, alexAccount);
            repoProvider.getVitoConfigurationRepository(WORKING_COPY).create(vitoAlexDynProviderTravelUAFlight);

            VitoConfigurationWorking vitoSergeyDynProviderMetroDEFlight = new VitoConfigurationWorking(true, SaleType.Total, vitoSergey, dynProviderMetroDEFlight, sergeyAccount);
            repoProvider.getVitoConfigurationRepository(WORKING_COPY).create(vitoSergeyDynProviderMetroDEFlight);
            VitoConfigurationWorking vitoSergeyDynProviderCinemaDEHotel = new VitoConfigurationWorking(true, SaleType.Total, vitoSergey, dynProviderCinemaDEHotel, sergeyAccount);
            repoProvider.getVitoConfigurationRepository(WORKING_COPY).create(vitoSergeyDynProviderCinemaDEHotel);
            VitoConfigurationWorking vitoSergeyDynProviderTravelDEFlight = new VitoConfigurationWorking(true, SaleType.Total, vitoSergey, dynProviderTravelDEFlight0, sergeyAccount);
            repoProvider.getVitoConfigurationRepository(WORKING_COPY).create(vitoSergeyDynProviderTravelDEFlight);
            repoProvider.getVitoConfigurationRepository(WORKING_COPY).commitTransaction();

            repoProvider.getPaymentSystemRepository().beginTransaction();
            PaymentSystemEntity paymentSystemVisa = getRepoProvider().getPaymentSystemRepository().findByCode(DeprecatedPaymentSystemDictionary.BANK_ACCOUNT);
            PaymentSystemEntity paymentSystemMaestro = getRepoProvider().getPaymentSystemRepository().findByCode(DeprecatedPaymentSystemDictionary.CREDIT_CARD);
            PaymentSystemEntity paymentSystemMasterCard = getRepoProvider().getPaymentSystemRepository().findByCode(DeprecatedPaymentSystemDictionary.AGENCY_COLLECTION);
            repoProvider.getPaymentSystemRepository().commitTransaction();

            repoProvider.getVitoPaymentSystemRepository(WORKING_COPY).beginTransaction();
            VitoPaymentSystemWorking vitoPaymentSystemYuraVisa = new VitoPaymentSystemWorking(vitoYura, paymentSystemVisa, yuryAccount, "y1");
            repoProvider.getVitoPaymentSystemRepository(WORKING_COPY).create(vitoPaymentSystemYuraVisa);
            VitoPaymentSystemWorking vitoPaymentSystemAlexVisa = new VitoPaymentSystemWorking(vitoAlex, paymentSystemVisa, alexAccount, "a1");
            repoProvider.getVitoPaymentSystemRepository(WORKING_COPY).create(vitoPaymentSystemAlexVisa);
            VitoPaymentSystemWorking vitoPaymentSystemAlexMaestro = new VitoPaymentSystemWorking(vitoAlex, paymentSystemMaestro, alexAccount, "a2");
            repoProvider.getVitoPaymentSystemRepository(WORKING_COPY).create(vitoPaymentSystemAlexMaestro);
            VitoPaymentSystemWorking vitoPaymentSystemSergeyVisa = new VitoPaymentSystemWorking(vitoSergey, paymentSystemVisa, sergeyAccount, "s1");
            repoProvider.getVitoPaymentSystemRepository(WORKING_COPY).create(vitoPaymentSystemSergeyVisa);
            VitoPaymentSystemWorking vitoPaymentSystemSergeyMaestro = new VitoPaymentSystemWorking(vitoSergey, paymentSystemMaestro, sergeyAccount, "s2");
            repoProvider.getVitoPaymentSystemRepository(WORKING_COPY).create(vitoPaymentSystemSergeyMaestro);
            VitoPaymentSystemWorking vitoPaymentSystemSergeyMasterCard = new VitoPaymentSystemWorking(vitoSergey, paymentSystemMasterCard, sergeyAccount, "s3");
            repoProvider.getVitoPaymentSystemRepository(WORKING_COPY).create(vitoPaymentSystemSergeyMasterCard);
            repoProvider.getVitoPaymentSystemRepository(WORKING_COPY).commitTransaction();

            repoProvider.getBankDetailRepository(WORKING_COPY).beginTransaction();
            BankDetailWorking bankSparYury = new BankDetailWorking(yuryAccount);
            bankSparYury.setVitoPaymentSystem(vitoPaymentSystemYuraVisa);
            bankSparYury.setAccountHolderFirstName("Yury");
            bankSparYury.setAccountHolderLastName("Dadychin");
            bankSparYury.setBankCode("SPAR");
            bankSparYury.setBankName("SPARBANK");
//            bankSparYury.setAccountNumber();
            bankSparYury.setBic("AD1200012030200359100100".getBytes("UTF-8"));
            bankSparYury.setIban("DABAIE2D".getBytes("UTF-8"));
            bankSparYury.setTtPaymentToken("ttSparToken");
            repoProvider.getBankDetailRepository(WORKING_COPY).create(bankSparYury);
            repoProvider.getBankDetailRepository(WORKING_COPY).commitTransaction();


            SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");

//            repoProvider.getTravelPeriodRepository(WORKING_COPY).beginTransaction();

            TravelPeriodObject tpYura = travelPeriodService.createTravelPeriod(WORKING_COPY, EN_GB_LOCALE,
                    vitoYura.getId(), "vitoYura:year", formatter.parse("01.01.2014"), yuryAccount.getTtAuthId());
            ITravelPeriodEntity travelPeriodYuraYear = repoProvider.getTravelPeriodRepository(WORKING_COPY).find(tpYura.getId());

            travelPeriodService.createTravelPeriod(WORKING_COPY, EN_GB_LOCALE, vitoSergey.getId(), "vitoSergey:first half of year",
                    formatter.parse("01.01.2014"), sergeyAccount.getTtAuthId());
            travelPeriodService.createTravelPeriod(WORKING_COPY, EN_GB_LOCALE, vitoSergey.getId(), "vitoSergey:second half of year",
                    formatter.parse("01.07.2014"), sergeyAccount.getTtAuthId());
            travelPeriodService.createTravelPeriod(WORKING_COPY, EN_GB_LOCALE, vitoAlex.getId(), "vitoAlex:quarter#1",
                    formatter.parse("01.12.2013"), alexAccount.getTtAuthId());

            travelPeriodService.createTravelPeriod(WORKING_COPY, EN_GB_LOCALE, vitoAlex.getId(), "vitoAlex:quarter#2",
                    formatter.parse("01.03.2014"), alexAccount.getTtAuthId());
            travelPeriodService.createTravelPeriod(WORKING_COPY, EN_GB_LOCALE, vitoAlex.getId(), "vitoAlex:quarter#3",
                    formatter.parse("01.06.2014"), alexAccount.getTtAuthId());
            travelPeriodService.createTravelPeriod(WORKING_COPY, EN_GB_LOCALE, vitoAlex.getId(), "vitoAlex:quarter#4",
                    formatter.parse("01.09.2014"), alexAccount.getTtAuthId());

//            repoProvider.getTravelPeriodRepository(WORKING_COPY).commitTransaction();

            repoProvider.getTravelDurationRepository().beginTransaction();
            final int durFrom = 1;
            final int durTo2 = 2;
            TravelDurationEntity travelDuration1 = new TravelDurationEntity(durFrom, durTo2);
            repoProvider.getTravelDurationRepository().create(travelDuration1);
            final int durTo3 = 3;
            TravelDurationEntity travelDuration2 = new TravelDurationEntity(durFrom, durTo3);
            repoProvider.getTravelDurationRepository().create(travelDuration2);
            final int durTo4 = 4;
            TravelDurationEntity travelDuration3 = new TravelDurationEntity(durFrom, durTo4);
            repoProvider.getTravelDurationRepository().create(travelDuration3);
            final int durTo5 = 5;
            TravelDurationEntity travelDuration4 = new TravelDurationEntity(durFrom, durTo5);
            repoProvider.getTravelDurationRepository().create(travelDuration4);
            final int durTo6 = 6;
            TravelDurationEntity travelDuration5 = new TravelDurationEntity(durFrom, durTo6);
            repoProvider.getTravelDurationRepository().create(travelDuration5);
            final int durTo7 = 7;
            TravelDurationEntity travelDuration6 = new TravelDurationEntity(durFrom, durTo7);
            repoProvider.getTravelDurationRepository().create(travelDuration6);
            repoProvider.getTravelDurationRepository().commitTransaction();

            repoProvider.getDynamixCustomerRepository().beginTransaction();
            DynamixCustomerEntity dynamixCustomerTT = new DynamixCustomerEntity("TravelTainment", "TT test dynamix customer");
            repoProvider.getDynamixCustomerRepository().create(dynamixCustomerTT);
            DynamixCustomerEntity dynamixCustomerAma = new DynamixCustomerEntity("Amadeus", "Amadeus test dynamix customer");
            repoProvider.getDynamixCustomerRepository().create(dynamixCustomerAma);
            repoProvider.getDynamixCustomerRepository().commitTransaction();

            final String aachenCity = "Aachen";
            final String titleMr = "Mr.";
            final String dearTitle = "Dear";
            final String julicherStreet = "Julicher Strasse";
            final String zipCode = "DE007";

            final String phone = "+49-007-007-007";
            final String fax = "+49-008-008-008";
            final String mobile = "+49-009-009-009";

            repoProvider.getVitoAddressRepository(WORKING_COPY).beginTransaction();
            VitoAddressWorking addressYura1 = new VitoAddressWorking(vitoYura, germany, titleMr, dearTitle, "Yura",
                    "Dadychin", julicherStreet, zipCode, aachenCity, phone, fax, mobile, "yuar.dadychin@cia.us", yuryAccount);
            repoProvider.getVitoAddressRepository(WORKING_COPY).create(addressYura1);
            VitoAddressWorking addressYura2 = new VitoAddressWorking(vitoYura, germany, titleMr, dearTitle, "Yura",
                    "Dadychin", julicherStreet, zipCode, aachenCity, phone, fax, mobile, "yuar.dadychin@cia.us", yuryAccount);
            repoProvider.getVitoAddressRepository(WORKING_COPY).create(addressYura2);
            VitoAddressWorking addressAlex1 = new VitoAddressWorking(vitoAlex, germany, titleMr, dearTitle, "Alex",
                    "Borlis", julicherStreet, zipCode, aachenCity, phone, fax, mobile, "alex.borlis@cia.us", alexAccount);
            repoProvider.getVitoAddressRepository(WORKING_COPY).create(addressAlex1);
            VitoAddressWorking addressAlex2 = new VitoAddressWorking(vitoAlex, germany, titleMr, dearTitle, "Alex",
                    "Borlis", julicherStreet, zipCode, aachenCity, phone, fax, mobile, "alex.borlis@cia.us", alexAccount);
            repoProvider.getVitoAddressRepository(WORKING_COPY).create(addressAlex2);
            VitoAddressWorking addressSergey1 = new VitoAddressWorking(vitoSergey, germany, titleMr, dearTitle, "Sergey",
                    "Mavrov", julicherStreet, zipCode, aachenCity, phone, fax, mobile, "james.bond@cia.us", sergeyAccount);
            repoProvider.getVitoAddressRepository(WORKING_COPY).create(addressSergey1);
            VitoAddressWorking addressSergey2 = new VitoAddressWorking(vitoSergey, germany, titleMr, dearTitle, "Sergey",
                    "Mavrov", julicherStreet, zipCode, aachenCity, phone, fax, mobile, "james.bond@cia.us", sergeyAccount);
            repoProvider.getVitoAddressRepository(WORKING_COPY).create(addressSergey2);
            repoProvider.getVitoAddressRepository(WORKING_COPY).commitTransaction();

            repoProvider.getVitoProviderRepository(WORKING_COPY).beginTransaction();
            VitoProviderWorking vitoProviderYuraCinemaUAHotel = new VitoProviderWorking(true, vitoYuraDynProviderCinemaUAHotel, yuryAccount);
            repoProvider.getVitoProviderRepository(WORKING_COPY).create(vitoProviderYuraCinemaUAHotel);
            VitoProviderWorking vitoProviderYuraMetroUAFlight = new VitoProviderWorking(true, vitoYuraDynProviderMetroUAFlight, yuryAccount);
            repoProvider.getVitoProviderRepository(WORKING_COPY).create(vitoProviderYuraMetroUAFlight);

            VitoProviderWorking vitoProviderAlexMetroUAFlight = new VitoProviderWorking(true, vitoAlexDynProviderMetroUAFlight, alexAccount);
            repoProvider.getVitoProviderRepository(WORKING_COPY).create(vitoProviderAlexMetroUAFlight);
            VitoProviderWorking vitoProviderAlexCinemaUAHotel = new VitoProviderWorking(true, vitoAlexDynProviderCinemaUAHotel, alexAccount);
            repoProvider.getVitoProviderRepository(WORKING_COPY).create(vitoProviderAlexCinemaUAHotel);
            VitoProviderWorking vitoProviderAlexTravelUAFlight = new VitoProviderWorking(false, vitoAlexDynProviderTravelUAFlight, alexAccount);
            repoProvider.getVitoProviderRepository(WORKING_COPY).create(vitoProviderAlexTravelUAFlight);

            VitoProviderWorking vitoProviderSergeyMetroDEFlight = new VitoProviderWorking(true, vitoSergeyDynProviderMetroDEFlight, sergeyAccount);
            repoProvider.getVitoProviderRepository(WORKING_COPY).create(vitoProviderSergeyMetroDEFlight);
            VitoProviderWorking vitoProviderSergeyCinemaDEHotel = new VitoProviderWorking(false, vitoSergeyDynProviderCinemaDEHotel, sergeyAccount);
            repoProvider.getVitoProviderRepository(WORKING_COPY).create(vitoProviderSergeyCinemaDEHotel);
            VitoProviderWorking vitoProviderSergeyTravelDEFlight = new VitoProviderWorking(false, vitoSergeyDynProviderTravelDEFlight, sergeyAccount);
            repoProvider.getVitoProviderRepository(WORKING_COPY).create(vitoProviderSergeyTravelDEFlight);
            repoProvider.getVitoProviderRepository(WORKING_COPY).commitTransaction();

            repoProvider.getBookingStrategyDecisionRepository().beginTransaction();
            BookingStrategyTypeEntity typeBC = new BookingStrategyTypeEntity("BC");
            repoProvider.getBookingStrategyTypeRepository().create(typeBC);
            BookingStrategyTypeEntity typeNX = new BookingStrategyTypeEntity("NX");
            repoProvider.getBookingStrategyTypeRepository().create(typeNX);
            BookingStrategyTypeEntity typeBQ = new BookingStrategyTypeEntity("BQ");
            repoProvider.getBookingStrategyTypeRepository().create(typeBQ);
            BookingStrategyDecisionEntity decisionSTOP = new BookingStrategyDecisionEntity("STOP");
            repoProvider.getBookingStrategyDecisionRepository().create(decisionSTOP);
            BookingStrategyDecisionEntity decisionCONTINUE = new BookingStrategyDecisionEntity("CONTINUE");
            repoProvider.getBookingStrategyDecisionRepository().create(decisionCONTINUE);
            //-=-=-
            BookingStrategyEntity bookingStrategyBCstop = new BookingStrategyEntity("STOP-BC", "", typeBC, decisionSTOP);
            repoProvider.getBookingStrategyRepository().create(bookingStrategyBCstop);
            BookingStrategyEntity bookingStrategyNXstop = new BookingStrategyEntity("STOP-NX", "", typeNX, decisionSTOP);
            repoProvider.getBookingStrategyRepository().create(bookingStrategyNXstop);
            BookingStrategyEntity bookingStrategyBQstop = new BookingStrategyEntity("STOP-BQ", "", typeBQ, decisionSTOP);
            repoProvider.getBookingStrategyRepository().create(bookingStrategyBQstop);
            BookingStrategyEntity bookingStrategyBCcontinue = new BookingStrategyEntity("CONT-BC", "", typeBC, decisionCONTINUE);
            repoProvider.getBookingStrategyRepository().create(bookingStrategyBCcontinue);
            BookingStrategyEntity bookingStrategyNXcontinue = new BookingStrategyEntity("CONT-NX", "", typeNX, decisionCONTINUE);
            repoProvider.getBookingStrategyRepository().create(bookingStrategyNXcontinue);
            BookingStrategyEntity bookingStrategyBQcontinue = new BookingStrategyEntity("CONT-BQ", "", typeBQ, decisionCONTINUE);
            repoProvider.getBookingStrategyRepository().create(bookingStrategyBQcontinue);
            repoProvider.getBookingStrategyDecisionRepository().commitTransaction();

            repoProvider.getCombinedBookingStrategyRepository().beginTransaction();
            CombinedBookingStrategyEntity combBookingCCC = new CombinedBookingStrategyEntity(bookingStrategyBCcontinue,
                    bookingStrategyBCcontinue, bookingStrategyNXcontinue);
            repoProvider.getCombinedBookingStrategyRepository().create(combBookingCCC);
            CombinedBookingStrategyEntity combBookingSSS = new CombinedBookingStrategyEntity(bookingStrategyBCstop,
                    bookingStrategyBQstop, bookingStrategyNXstop);
            repoProvider.getCombinedBookingStrategyRepository().create(combBookingSSS);
            CombinedBookingStrategyEntity combBookingCSC = new CombinedBookingStrategyEntity(bookingStrategyBCcontinue,
                    bookingStrategyBQstop, bookingStrategyNXcontinue);
            repoProvider.getCombinedBookingStrategyRepository().create(combBookingCSC);
            repoProvider.getCombinedBookingStrategyRepository().commitTransaction();

            repoProvider.getVitoProviderXVitoBookingInfoRepository(WORKING_COPY).beginTransaction();
            VitoProviderXVitoBookingInfoWorking vitoProviderYuraCinemaUAHotelBooking1 =
                    new VitoProviderXVitoBookingInfoWorking(vitoProviderYuraCinemaUAHotel, addressYura1, vitoPaymentSystemYuraVisa, combBookingCCC, yuryAccount);
            repoProvider.getVitoProviderXVitoBookingInfoRepository(WORKING_COPY).create(vitoProviderYuraCinemaUAHotelBooking1);
//            VitoProviderXVitoBookingInfoWorking vitoProviderYuraCinemaUAHotelBooking2 =
//                    new VitoProviderXVitoBookingInfoWorking(vitoProviderYuraCinemaUAHotel, addressYura2, vitoPaymentSystemYuraVisa, combBookingSSS, yuryAccount);
//            repoProvider.getVitoProviderXVitoBookingInfoRepository(WORKING_COPY).create(vitoProviderYuraCinemaUAHotelBooking2);

            VitoProviderXVitoBookingInfoWorking vitoProviderAlexMetroUAFlightBooking1 =
                    new VitoProviderXVitoBookingInfoWorking(vitoProviderAlexMetroUAFlight, addressAlex1, vitoPaymentSystemAlexMaestro, combBookingCCC, alexAccount);
            repoProvider.getVitoProviderXVitoBookingInfoRepository(WORKING_COPY).create(vitoProviderAlexMetroUAFlightBooking1);
//            VitoProviderXVitoBookingInfoWorking vitoProviderAlexMetroUAFlightBooking2 =
//                    new VitoProviderXVitoBookingInfoWorking(vitoProviderAlexMetroUAFlight, addressAlex1, vitoPaymentSystemAlexMaestro, combBookingSSS, alexAccount);
//            repoProvider.getVitoProviderXVitoBookingInfoRepository(WORKING_COPY).create(vitoProviderAlexMetroUAFlightBooking2);
            VitoProviderXVitoBookingInfoWorking vitoProviderAlexCinemaUAHotelBooking1 =
                    new VitoProviderXVitoBookingInfoWorking(vitoProviderAlexCinemaUAHotel, addressAlex1, vitoPaymentSystemAlexMaestro, combBookingCSC, alexAccount);
            repoProvider.getVitoProviderXVitoBookingInfoRepository(WORKING_COPY).create(vitoProviderAlexCinemaUAHotelBooking1);
            VitoProviderXVitoBookingInfoWorking vitoProviderAlexTravelUAFlightBooking1 =
                    new VitoProviderXVitoBookingInfoWorking(vitoProviderAlexTravelUAFlight, addressAlex2, vitoPaymentSystemAlexVisa, combBookingCSC, alexAccount);
            repoProvider.getVitoProviderXVitoBookingInfoRepository(WORKING_COPY).create(vitoProviderAlexTravelUAFlightBooking1);
            repoProvider.getVitoProviderXVitoBookingInfoRepository(WORKING_COPY).commitTransaction();

            repoProvider.getVitoProviderConfigurationRepository(WORKING_COPY).beginTransaction();
            final int relDays = 7;
            VitoProviderConfigurationWorking vitoProviderConfigurationYura =
                    new VitoProviderConfigurationWorking(true, relDays, (TravelPeriodWorking)travelPeriodYuraYear, vitoProviderYuraMetroUAFlight, yuryAccount);
            repoProvider.getVitoProviderConfigurationRepository(WORKING_COPY).create(vitoProviderConfigurationYura);
            repoProvider.getVitoProviderConfigurationRepository(WORKING_COPY).commitTransaction();

            logger.info("create the db -> finished");

        } catch (UnsupportedEncodingException en) {
            logger.log(Level.SEVERE, "The exception has been registered during init demo env - unsupported encoding UTF-8", en);
            Assert.fail("TEST FAILED ON INIT ENVIRONMENT!");
        } catch (ParseException t) {
            logger.log(Level.SEVERE, "The exception has been registered during init demo env - check travel period parsing", t);
            Assert.fail("TEST FAILED ON INIT ENVIRONMENT!");
        } catch (IllegalStateException t) {
            logger.log(Level.SEVERE, "The exception has been registered during init demo env - check parameters", t);
            Assert.fail("TEST FAILED ON INIT ENVIRONMENT!");
        } catch (PersistenceException t) {
            logger.log(Level.SEVERE, "The exception has been registered during init demo env - check hibernate", t);
            Assert.fail("TEST FAILED ON INIT ENVIRONMENT!");
        } catch (ServerException e) {
            logger.log(Level.SEVERE, "The exception has been registered during init demo env - check hibernate", e);
            Assert.fail("TEST FAILED ON INIT ENVIRONMENT!");
        } finally {
            if (getEm().getTransaction().isActive()) {
                getEm().getTransaction().rollback();
            }
        }
    }

    public DynamixAccountEntity getTtuser() {
        return ttuser;
    }

    public DynamixAccountEntity getTtadmin() {
        return ttadmin;
    }

    public DynamixAccountEntity getVitouser() {
        return vitouser;
    }

    public DynamixAccountEntity getVitosupervisor() {
        return vitosupervisor;
    }
}
